package com.qingyun.auth.controller;


import com.qingyun.auth.entity.User;
import com.qingyun.common.dto.Result;
import com.qingyun.auth.dto.LoginFormDTO;
import com.qingyun.auth.dto.UserPassWordDTO;
import com.qingyun.auth.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;


@Slf4j
@RestController
public class UserController {
    @Autowired
    private IUserService userServiceImpl;

    @PostMapping("/login")
    public Result login(@RequestBody LoginFormDTO loginForm, HttpSession session){
        //用户登录功能
        return userServiceImpl.userLogin(loginForm,session);
    }

    @PostMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token) {
        // 调用Service处理退出逻辑
        return userServiceImpl.logout(token);
    }

    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestHeader("Authorization") String token,@RequestBody UserPassWordDTO userPassWordDTO){
        return userServiceImpl.updatePassword(token,userPassWordDTO);
    }

    @GetMapping("/internal/byId")
    public User getById(@RequestParam("TeacherId") Long teacherId){
        return  userServiceImpl.getBaseMapper().selectById(teacherId);
    }
}
